import { Component } from "react";
import { Form, Input, Button }  from "antd";
import {login} from "../../api/user";
class Login extends Component{
    constructor(props){
        super(props);
        this.onFinish = this.onFinish.bind(this);
    }
    onFinish(data){
       login(data).then(res => {
           this.props.history.push("/home")
       })
    }
    render(){
        return (
            <Form
                name="basic"
                labelCol={{ span: 8 }}
                wrapperCol={{ span: 16 }}
                initialValues={{ remember: true }}
                onFinish={this.onFinish}
                >
                <Form.Item
                    label="请输入手机号"
                    name="phone"
                    rules={[{ required: true, message: '请输入手机号' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="密码"
                    name="password"
                    rules={[{ required: true, message: '请输入密码' }]}
                >
                    <Input.Password />
                </Form.Item>

                <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                    <Button type="primary" htmlType="submit">
                        登录
                    </Button>
                </Form.Item>
            </Form>
        )
    }
}
export default Login;